﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">


<head>


<body style="margin: 0; background-color: #000; color: #FFFFFF;">


<meta http-equiv="Content-Type" content="text/html" />


<title>HJSplit MOD - Devils</title>


<style type="text/css">


.style1 {


	text-align: center;


}


.style2 {


	background-image: url('../images/background_pm.gif');


}


.style3 {


	text-align: left;


}


</style>


</head>


<div class="style3">


<table style="width: 100%" cellspacing="0" cellpadding="0" class="style2">


	<tr>


		<td class="style1" style="height: 61px">


		<img alt="" src="../templates/plugmod/images/logo_pm.gif" width="363" height="61"></td>


	</tr>


	<tr>


		<td class="style1" style="height: 419px" valign="top">


		<br>


<DIV ALIGN="CENTER">


	<P ALIGN="CENTER"><FONT FACE="Arial"><input TYPE="button" VALUE="Close"


  onClick="window.close()"></FONT></P>


</DIV>		


<?php


$filename = $_POST['arquivo'];


$tamanho = $_POST['tamanho'];


if(!ctype_digit($tamanho) or empty($tamanho)){


	?>


    <script language="javascript">


	alert("Por favor tente novamente! ");


	history.go(-1);


	</script>


<?php


}


?>


<?php


/*


 --------------------------------------------------


 filesplit.php HJSplit compatiple PHP file splitter


 --------------------------------------------------


 


 File name: 


	filesplit.php                


 Author: 


	Umit Tirpan 2007-03-22          


	Umit Tirpan 2008-03-12 [remote file support added]         


 Author's Website: 


	http://forum.iyinet.com/





 Description:


	This PHP script, splits the files into smaller pieces in binary.


	It is compatiple with HJSplit, so you can re-join splitted files using HJSplit's Join utility.


	It can split a file up to 999 pieces.





 What is the use, why will I use this?


	Some webmasters do not have shell access to their websites. This prevents them splitting big files, ie. MySQL backups, into smaller files. Splitting a 200Mb file into 10 x 20Mb file may be easy on webmaster to download in pieces. 


 


 How to run:


	Make sure your webserver has write permission on the target folder.


	Edit variables. 


	Upload (ftp) this file to your webserver or run on your PC.


	For security reason, filename is hardcoded. You can modify code to accept $_GET['filename']





 Run with your favorite browser.


	http://www.<your-web-site>.com/filesplit.php


 Or run on shell (ie. ssh)


	php filesplit.php





 It is Ok to share and modify this code and use in/with your applications. No restrictions.





 */














// ---------------------------


// Edit variables (3 variables)


// ---------------------------





// File to split, is its not in the same folder with filesplit.php, full path is required.


//$filename = $_GET['file']; 





// Target folder. Splitted files will be stored here. Original file never gets touched.


// Do not append slash! Make sure webserver has write permission on this folder.


$targetfolder = '../files';





// File size in Mb per piece/split. 


// For a 200Mb file if piecesize=10 it will create twenty 10Mb files


$piecesize = $tamanho; // splitted file size in MB











// ---------------------------


// Do NOT edit this section


// ---------------------------





$buffer = 1024;


$piece = 1048576*$piecesize;


$current = 0;


$splitnum = 1;





if(!file_exists($targetfolder)) {


	if(mkdir($targetfolder)) {


		echo "Destination Folder $targetfolder Created! ".br();


	}


}





if(!$handle = fopen("../files/$filename", "rb")) {


	die("Unable To Open File $filename For Reading! Ensure that the file is configured correctly split.php!".br());


}





$base_filename = basename($filename);





$piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);


if(!$fw = fopen($piece_name,"w")) {


	die("Unable to open $piece_name for write. Make sure target folder is writeable.".br());


}


echo "Trimming The File $base_filename In Parts Of $piecesize Mb ".br()."(The Last Part May Have a Smaller Size)".br();


echo "Creating File: $piece_name...".br();


while (!feof($handle) and $splitnum < 999) {


	if($current < $piece) {


		if($content = fread($handle, $buffer)) {


			if(fwrite($fw, $content)) {


				$current += $buffer;


			} else {


				die("split.php is unable to write files in the directory. The destination folder does not have permission to write! Try running the command chmod + w on the destination folder".br());


			}


		}


	} else {


		fclose($fw);


		$current = 0;


		$splitnum++;


		$piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);


		echo "Creating File: $piece_name...".br();


		$fw = fopen($piece_name,"w");


	}


}


fclose($fw);


fclose($handle);


echo "Finalized! ".br();


exit;





function br() {


	return (!empty($_SERVER['SERVER_SOFTWARE']))?'<br>':"\n";


}


?>


		<br />


		</td>


	</tr>


</table>


	</div>


</body>


</html>